#include<stdio.h>

void select_sort(int *data,int offset,int length){
		int i , j;
		for( i=offset+length-1;i>=offset;i--){
				int k=i;
				for( j=offset;j<i;j++){
					if(data[j]<data[k]) k=j;
				}
				if(k!=i){
					int tmp = data[k];
					data[k]=data[i];
					data[i] = tmp;
				}
		}
	
}

void bubble_sort(int * data,int offset,int length){
	int tag = 1;
	int j,i;
	for( j=offset+length-1;j>-1&&tag;j--){
		tag = 0;
		for( i=offset;i<j;i++){
			if(data[i]>data[i+1]){
				int tmp=data[i];
				data[i]=data[i+1];
				data[i+1]=tmp;
				tag=1;
			}
		}	
	}
}



void q_sort(int * data,int left,int right){
	int l=left;
	int r=right;
	int pivot = (left+right)/2;
	
	while(l<r){
		for(;data[pivot]>data[l];l++);
		for(;data[pivot]<data[r];r--);
		if(l<=r){
			int tmp=data[l];
			data[l]=data[r];
			data[r]=tmp;
			l++;
			r--;
		}
	}
	if(l<right)
		q_sort(data,l,right);
	if(r>left)
		q_sort(data,left,r);

}
// 2 3 5 5 6 7 
 void insert_sort(int * data,int offset,int length){
		int i=offset;
		for(;i<offset+length-1;i++){
			int swap = data[i+1];
			int j=i;
			for(;data[j]>swap&&j>=offset;j--) data[j+1]=data[j];
			if(j!=i+1){
				data[j+1] = swap ;
			}
		}
}



int main(void){
	int data[]={3,1,2,5,7,4,6,9,8,0};
	int data1[]={0,1,2,3,4,5,6,7,8,9};
	int l=0;

	insert_sort(data1,0,10);

	for( l=0;l<10;l++){
		printf("%d ",data1[l]);
	}
	return 0;
}